package jpf.nextsearch.base;

import jpf.nextsearch.exception.InitializationException;

import org.apache.log4j.Logger;

/**
 * @author <a href="mailto:jacek.pruszkowski@gmail.com">Jacek Pruszkowski</a>
 */
public class GenericObject implements GenericObjectInterface {
	
	private boolean loggingDebug;
	private boolean loggingError;
	private boolean loggingWarning;
	private boolean loggingInfo;
	private GlobalConfiguration globalConfiguration;
	private Logger logger;
	
	public GenericObject() {
		setLogger(Logger.getLogger(this.getClass()));
	}
	
	/**
	 * @return the loggingDebug
	 */
	public boolean isLoggingDebug() {
		return loggingDebug;
	}
	
	/**
	 * @param loggingDebug
	 *            the loggingDebug to set
	 */
	public void setLoggingDebug(boolean loggingDebug) {
		this.loggingDebug = loggingDebug;
	}
	
	/**
	 * @return the loggingError
	 */
	public boolean isLoggingError() {
		return loggingError;
	}
	
	/**
	 * @param loggingError
	 *            the loggingError to set
	 */
	public void setLoggingError(boolean loggingError) {
		this.loggingError = loggingError;
	}
	
	/**
	 * @return the loggingWarning
	 */
	public boolean isLoggingWarning() {
		return loggingWarning;
	}
	
	/**
	 * @param loggingWarning
	 *            the loggingWarning to set
	 */
	public void setLoggingWarning(boolean loggingWarning) {
		this.loggingWarning = loggingWarning;
	}
	
	/**
	 * @return the loggingInfo
	 */
	public boolean isLoggingInfo() {
		return loggingInfo;
	}
	
	/**
	 * @param loggingInfo
	 *            the loggingInfo to set
	 */
	public void setLoggingInfo(boolean loggingInfo) {
		this.loggingInfo = loggingInfo;
	}
	
	/**
	 * @return the globalConfiguration
	 */
	public GlobalConfiguration getGlobalConfiguration() {
		return globalConfiguration;
	}
	
	/**
	 * @param globalConfiguration
	 *            the globalConfiguration to set
	 */
	public void setGlobalConfiguration(GlobalConfiguration globalConfiguration) {
		this.globalConfiguration = globalConfiguration;
	}
	
	/**
	 * Get the value of logger
	 * 
	 * @return the value of logger
	 */
	public Logger getLogger() {
		return logger;
	}
	
	/**
	 * Set the value of logger
	 * 
	 * @param logger
	 *            new value of logger
	 */
	public void setLogger(Logger logger) {
		this.logger = logger;
	}
	
	public void init() throws InitializationException {
		if (isLoggingInfo()) {
			getLogger().info(
				"Initialising " + getClass().getName() + " object instance");
		}
	}
	
	public void destroy() {
		if (isLoggingInfo()) {
			getLogger().info(
				"Destroying " + getClass().getName() + " object instance");
		}
	}
}
